package com.dcjt.firehotcarpad.fragment

import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.aries.library.fast.basis.BasisFragment
import com.aries.library.fast.manager.LoggerManager
import com.aries.library.fast.manager.TabLayoutManager
import com.dcjt.firehotcarpad.R
import com.dcjt.firehotcarpad.utils.MarkerToMapType
import com.flyco.tablayout.SlidingTabLayout
import com.flyco.tablayout.listener.OnTabSelectListener

/**
 * Created by cj on 2021/2/20.
 * Email:codesexy@163.com
 * Function:
 * desc:
 */

abstract class BaseTabsFragment : BasisFragment() {

    protected lateinit var bottomContainer:FrameLayout

    protected var currentIndex:Int = 0
    public var tabLayoutSliding:SlidingTabLayout ?= null

    override fun getContentLayout(): Int = R.layout.fragment_system_operation

    override fun initView(savedInstanceState: Bundle?) {
        tabLayoutSliding = findViewById<SlidingTabLayout>(R.id.tabLayout_sliding)
        var vpContent = findViewById<ViewPager>(R.id.vp_contentFastLib)
        bottomContainer = findViewById<FrameLayout>(R.id.bottomContainer)!!
        tabLayoutSliding?.textsize = 14f

        TabLayoutManager.getInstance().setSlidingTabData(
            this, tabLayoutSliding, vpContent,
            getTabTitles(), getFragments()
        )

        vpContent?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                currentIndex = position
                when(currentIndex){
                    //显示警情列表
                    0-> {
                        MapOperationEventPool.get().sendAroundWaterMakersDispatch(null, MarkerToMapType.MARKER_HINT)
                        MapOperationEventPool.get().sendDisasterMakersDispatch(null,
                            MarkerToMapType.MARKER_SHOW,0)
                    }
                    //显示水源
                    1-> {
                        MapOperationEventPool.get().sendAroundWaterMakersDispatch(null,
                            MarkerToMapType.MARKER_SHOW)
                        MapOperationEventPool.get().sendDisasterMakersDispatch(null,
                            MarkerToMapType.MARKER_HINT)
                    }
                }
                onPageChange(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })
    }

    protected abstract fun getTabTitles(): List<String>

    protected abstract fun getFragments(): List<Fragment>

    open fun onPageChange(index: Int) {
        when(index){
            //显示警情列表
            0-> {
                MapOperationEventPool.get().sendAroundWaterMakersDispatch(null, MarkerToMapType.MARKER_HINT)
                MapOperationEventPool.get().sendDisasterMakersDispatch(null,
                    MarkerToMapType.MARKER_SHOW)
            }
            //显示水源
            1-> {
                MapOperationEventPool.get().sendAroundWaterMakersDispatch(null,
                    MarkerToMapType.MARKER_SHOW)
                MapOperationEventPool.get().sendDisasterMakersDispatch(null,
                    MarkerToMapType.MARKER_HINT)
            }
        }

    }


}